package com.wuxinwudai.android.app;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wuxinwudai.android.R;

/**
 * LinearLayoutActivity 类是自带 TitleBar 的 Activity 类
 * @author 吾心无待 于2016年03月01日
 */
public abstract class LinearLayoutActivity extends BaseActivity{
    public ImageView ivLeft;//左边图片
    public ImageView ivDivider;//分割符
    public TextView tvTitle;//标题
    public ImageView ivRight;//右边图片
    protected RelativeLayout rlHead;//顶部标题栏
    protected LinearLayout lyContainer;//内部容器
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_base_layout);
        initView();
        setChildView();
    }

    /**
     * 抽象方法，获取子视图布局 ID
     * @return 布局资源 ID
     */
    public abstract int getLayoutId();



    //初始化 title_bar 等
    private void initView(){
        ivLeft = (ImageView)findViewById(R.id.iv_left);
        ivDivider = (ImageView)findViewById(R.id.iv_divider);
        tvTitle = (TextView)findViewById(R.id.tv_title);
        ivRight = (ImageView)findViewById(R.id.iv_right);
        lyContainer = (LinearLayout)findViewById(R.id.ly_container);
        rlHead = (RelativeLayout)findViewById(R.id.rl_head);
        ivLeft.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    /**
     * 设置容器内部布局方向
     * @param orientation LinearLayout 的布局方向
     */
    public void setOrientation(int orientation){
        lyContainer.setOrientation(orientation);
    }

    /**
     * 设置容器内的视图，可用于重写
     */
    protected void setChildView(){
        View v = getLayoutInflater().inflate(getLayoutId(),lyContainer,false);
        lyContainer.addView(v);
    }
}
